﻿//==================================================================
// Copyright (C) 2011 深圳市中旭企业管理股份有限公司
// 文件名: CrmDeliverTrain.cs
// 作 者：代码自动生成
// 日 期：2012-4-24 10:48:05
// 描 述：
// 版 本：1.00
// 修改历史纪录
// 版 本  修改时间      修改人            修改内容
// 1.00             
//==================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using System.Text;
using Csla;
using lite;
using Csla.Validation;
using Csla.Data;
using System.Data.SqlClient;
using ZX.DAL;
using OpenExpressApp.ORM;

namespace ZX.CRM.Library
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    [Table(Name = "CrmDeliverTrain")]
    [ZX.DBModule.Table("CrmDeliverTrain", "ID")]
    public class CrmDeliverTrain : ZX.DBModule.BaseEntity
    {

        #region Business Methods 业务方法

        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<Guid> IDProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<Guid>("ID"));
        [DataObjectField(true, true)]
        [Column, PK]
        public Guid ID
        {
            get { return GetProperty(IDProperty); }
            set { SetProperty(IDProperty, value); }
        }

        /// <summary>
        /// 交付申请单单号
        /// </summary>
        private static PropertyInfo<string> CodeProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<string>("Code"));
        [Column]
        public string Code
        {
            get { return GetProperty(CodeProperty); }
            set { SetProperty(CodeProperty, value); }
        }
        /// <summary>
        /// 订单产品ID
        /// </summary>
        private static PropertyInfo<Guid> OrderProductIDProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<Guid>("OrderProductID"));
        [Column]
        public Guid OrderProductID
        {
            get { return GetProperty(OrderProductIDProperty); }
            set { SetProperty(OrderProductIDProperty, value); }
        }
        /// <summary>
        /// 是否独立内训
        /// </summary>
        private static PropertyInfo<string> IsSingleTrainProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<string>("IsSingleTrain"));
        [Column]
        public string IsSingleTrain
        {
            get { return GetProperty(IsSingleTrainProperty); }
            set { SetProperty(IsSingleTrainProperty, value); }
        }
        /// <summary>
        /// 内训天数
        /// </summary>
        private static PropertyInfo<decimal> TrainSumProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<decimal>("TrainSum"));
        [Column]
        public decimal TrainSum
        {
            get { return GetProperty(TrainSumProperty); }
            set { SetProperty(TrainSumProperty, value); }
        }
        /// <summary>
        /// 内训开始时间
        /// </summary>
        private static PropertyInfo<DateTime> BeginDateProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<DateTime>("BeginDate"));
        [Column]
        public DateTime BeginDate
        {
            get { return GetProperty(BeginDateProperty); }
            set { SetProperty(BeginDateProperty, value); }
        }
        /// <summary>
        /// 内训结案时间
        /// </summary>
        private static PropertyInfo<DateTime> EndDateProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<DateTime>("EndDate"));
        [Column]
        public DateTime EndDate
        {
            get { return GetProperty(EndDateProperty); }
            set { SetProperty(EndDateProperty, value); }
        }
        /// <summary>
        /// 内训天数
        /// </summary>
        private static PropertyInfo<decimal> DateSumProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<decimal>("DateSum"));
        [Column]
        public decimal DateSum
        {
            get { return GetProperty(DateSumProperty); }
            set { SetProperty(DateSumProperty, value); }
        }
        /// <summary>
        /// 成功度
        /// </summary>
        private static PropertyInfo<decimal> SucceedDegreeProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<decimal>("SucceedDegree"));
        [Column]
        public decimal SucceedDegree
        {
            get { return GetProperty(SucceedDegreeProperty); }
            set { SetProperty(SucceedDegreeProperty, value); }
        }
        /// <summary>
        /// 内部评价
        /// </summary>
        private static PropertyInfo<string> InnerValueProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<string>("InnerValue"));
        [Column]
        public string InnerValue
        {
            get { return GetProperty(InnerValueProperty); }
            set { SetProperty(InnerValueProperty, value); }
        }
        /// <summary>
        /// 外部评价
        /// </summary>
        private static PropertyInfo<string> OutValueProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<string>("OutValue"));
        [Column]
        public string OutValue
        {
            get { return GetProperty(OutValueProperty); }
            set { SetProperty(OutValueProperty, value); }
        }
        /// <summary>
        /// 满意度
        /// </summary>
        private static PropertyInfo<decimal> WellDegreeProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<decimal>("WellDegree"));
        [Column]
        public decimal WellDegree
        {
            get { return GetProperty(WellDegreeProperty); }
            set { SetProperty(WellDegreeProperty, value); }
        }
        /// <summary>
        /// 启动者
        /// </summary>
        private static PropertyInfo<Guid> StartUserProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<Guid>("StartUser"));
        [Column]
        public Guid StartUser
        {
            get { return GetProperty(StartUserProperty); }
            set { SetProperty(StartUserProperty, value); }
        }
        /// <summary>
        /// 启动日期
        /// </summary>
        private static PropertyInfo<DateTime> StartDateProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<DateTime>("StartDate"));
        [Column]
        public DateTime StartDate
        {
            get { return GetProperty(StartDateProperty); }
            set { SetProperty(StartDateProperty, value); }
        }
        /// <summary>
        /// 讲师成员
        /// </summary>
        private static PropertyInfo<string> PTeacherProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<string>("PTeacher"));
        [Column]
        public string PTeacher
        {
            get { return GetProperty(PTeacherProperty); }
            set { SetProperty(PTeacherProperty, value); }
        }
        /// <summary>
        /// 内训部填写人
        /// </summary>
        private static PropertyInfo<Guid> TrainUserProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<Guid>("TrainUser"));
        [Column]
        public Guid TrainUser
        {
            get { return GetProperty(TrainUserProperty); }
            set { SetProperty(TrainUserProperty, value); }
        }
        /// <summary>
        /// 内训部填写时间
        /// </summary>
        private static PropertyInfo<DateTime> TrainDateProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<DateTime>("TrainDate"));
        [Column]
        public DateTime TrainDate
        {
            get { return GetProperty(TrainDateProperty); }
            set { SetProperty(TrainDateProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<string> TrainExplainProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<string>("TrainExplain"));
        [Column]
        public string TrainExplain
        {
            get { return GetProperty(TrainExplainProperty); }
            set { SetProperty(TrainExplainProperty, value); }
        }
        /// <summary>
        /// 负责交付的人
        /// </summary>
        private static PropertyInfo<Guid> ClassFrontServerProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<Guid>("ClassFrontServer"));
        [Column]
        public Guid ClassFrontServer
        {
            get { return GetProperty(ClassFrontServerProperty); }
            set { SetProperty(ClassFrontServerProperty, value); }
        }
        /// <summary>
        /// 说明
        /// </summary>
        private static PropertyInfo<string> ExplainProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<string>("Explain"));
        [Column]
        public string Explain
        {
            get { return GetProperty(ExplainProperty); }
            set { SetProperty(ExplainProperty, value); }
        }
        /// <summary>
        /// 市场部填写人
        /// </summary>
        private static PropertyInfo<Guid> DegreeUserProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<Guid>("DegreeUser"));
        [Column]
        public Guid DegreeUser
        {
            get { return GetProperty(DegreeUserProperty); }
            set { SetProperty(DegreeUserProperty, value); }
        }
        /// <summary>
        /// 市场部填写时间
        /// </summary>
        private static PropertyInfo<DateTime> DegreeDateProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<DateTime>("DegreeDate"));
        [Column]
        public DateTime DegreeDate
        {
            get { return GetProperty(DegreeDateProperty); }
            set { SetProperty(DegreeDateProperty, value); }
        }
        /// <summary>
        /// 添加人、
        /// </summary>
        private static PropertyInfo<Guid> AddUserProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<Guid>("AddUser"));
        [Column]
        public Guid AddUser
        {
            get { return GetProperty(AddUserProperty); }
            set { SetProperty(AddUserProperty, value); }
        }
        /// <summary>
        /// 添加时间
        /// </summary>
        private static PropertyInfo<DateTime> AddTimeProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<DateTime>("AddTime"));
        [Column]
        public DateTime AddTime
        {
            get { return GetProperty(AddTimeProperty); }
            set { SetProperty(AddTimeProperty, value); }
        }
        /// <summary>
        /// 交付单状态
        /// </summary>
        private static PropertyInfo<Guid> DliverStateProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<Guid>("DliverState"));
        [Column]
        public Guid DliverState
        {
            get { return GetProperty(DliverStateProperty); }
            set { SetProperty(DliverStateProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<string> exp2Property = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<string>("exp2"));
        [Column]
        public string exp2
        {
            get { return GetProperty(exp2Property); }
            set { SetProperty(exp2Property, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<string> exp3Property = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<string>("exp3"));
        [Column]
        public string exp3
        {
            get { return GetProperty(exp3Property); }
            set { SetProperty(exp3Property, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<string> exp4Property = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<string>("exp4"));
        [Column]
        public string exp4
        {
            get { return GetProperty(exp4Property); }
            set { SetProperty(exp4Property, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<string> exp1Property = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<string>("exp1"));
        [Column]
        public string exp1
        {
            get { return GetProperty(exp1Property); }
            set { SetProperty(exp1Property, value); }
        }
        /// <summary>
        /// 流程ID
        /// </summary>
        private static PropertyInfo<string> WorkFlowIdProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<string>("WorkFlowId"));
        [Column]
        public string WorkFlowId
        {
            get { return GetProperty(WorkFlowIdProperty); }
            set { SetProperty(WorkFlowIdProperty, value); }
        }
        /// <summary>
        /// 流程实例ID
        /// </summary>
        private static PropertyInfo<string> WorkFlowInsIdProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<string>("WorkFlowInsId"));
        [Column]
        public string WorkFlowInsId
        {
            get { return GetProperty(WorkFlowInsIdProperty); }
            set { SetProperty(WorkFlowInsIdProperty, value); }
        }
        /// <summary>
        /// 任务ID
        /// </summary>
        private static PropertyInfo<string> WorkTaskIdProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<string>("WorkTaskId"));
        [Column]
        public string WorkTaskId
        {
            get { return GetProperty(WorkTaskIdProperty); }
            set { SetProperty(WorkTaskIdProperty, value); }
        }
        /// <summary>
        /// 任务实例ID
        /// </summary>
        private static PropertyInfo<string> WorkTaskInsIdProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<string>("WorkTaskInsId"));
        [Column]
        public string WorkTaskInsId
        {
            get { return GetProperty(WorkTaskInsIdProperty); }
            set { SetProperty(WorkTaskInsIdProperty, value); }
        }

        /// <summary>
        /// 客户经理
        /// </summary>
        private static PropertyInfo<Guid> CustomerMgrProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<Guid>("CustomerMgr"));
        [Column]
        public Guid CustomerMgr
        {
            get { return GetProperty(CustomerMgrProperty); }
            set { SetProperty(CustomerMgrProperty, value); }
        }
        /// <summary>
        /// 客户总监
        /// </summary>
        private static PropertyInfo<Guid> CustomerDirectorProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<Guid>("CustomerDirector"));
        [Column]
        public Guid CustomerDirector
        {
            get { return GetProperty(CustomerDirectorProperty); }
            set { SetProperty(CustomerDirectorProperty, value); }
        }
        /// <summary>
        /// 分总
        /// </summary>
        private static PropertyInfo<Guid> CustomerManagerProperty = RegisterProperty(typeof(CrmDeliverTrain), new PropertyInfo<Guid>("CustomerManager"));
        [Column]
        public Guid CustomerManager
        {
            get { return GetProperty(CustomerManagerProperty); }
            set { SetProperty(CustomerManagerProperty, value); }
        }
        #endregion

        #region Validation Rules 验证规则
        //将验证规则与业务对象的属性联系在一起
        protected override void AddBusinessRules()
        {
            //AddRule的第一个参数是委托变量，也就是说是方法的变量
            ValidationRules.AddRule(CommonRules.StringRequired, "Code");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Code", 10));
            ValidationRules.AddRule(CommonRules.StringRequired, "IsSingleTrain");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("IsSingleTrain", 1));
            ValidationRules.AddRule(CommonRules.StringRequired, "InnerValue");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("InnerValue", 500));
            ValidationRules.AddRule(CommonRules.StringRequired, "OutValue");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("OutValue", 500));
            ValidationRules.AddRule(CommonRules.StringRequired, "PTeacher");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("PTeacher", 500));
            ValidationRules.AddRule(CommonRules.StringRequired, "TrainExplain");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("TrainExplain", 500));
            ValidationRules.AddRule(CommonRules.StringRequired, "Explain");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Explain", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "exp2");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("exp2", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "exp3");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("exp3", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "exp4");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("exp4", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "exp1");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("exp1", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "WorkFlowId");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("WorkFlowId", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "WorkFlowInsId");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("WorkFlowInsId", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "WorkTaskId");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("WorkTaskId", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "WorkTaskInsId");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("WorkTaskInsId", 50));
            //base.AddBusinessRules();
        }
        #endregion

        #region Factory Methods 工厂方法

        public CrmDeliverTrain() { }

        public static CrmDeliverTrain New()
        {
            return DataPortal.Create<CrmDeliverTrain>();
        }
        public static CrmDeliverTrain Get(Guid ID)
        {
            return DataPortal.Fetch<CrmDeliverTrain>(new SingleLazyCriteria<CrmDeliverTrain, Guid>(ID, false));
        }
        public static void Delete(Guid ID)
        {
            DataPortal.Delete(ID);
        }

        //public override CrmDeliverTrain Save()
        //{
        //return base.Save();
        //}
        #endregion

        #region Data Access 数据访问
        //由于DataPortal_create中没有对数据库的访问，所有标记了Runlocal特性，使得该方法只需在本地运行即可
        //如果代码中有访问数据库的方法，那么就不要用这个特性，使数据门户可以根据情况将此方法的运行选择在应用服务器还是本地
        [RunLocal()]
        protected override void DataPortal_Create()
        {
            //在此调用CheckRules对所有的属性进行验证规则的检查，这样检查只运行一次。
            ValidationRules.CheckRules();
        }


        //可以看到此方法没有标记任何特性
        //此方法要访问数据库所以不能标记本地，由于她没有任何数据库更新操作所以也无需事务性的保护
        //此方法调用结束后会隐含的调用MarkOld（）方法
        private void DataPortal_Fetch(Guid ID)
        {
            //通过连接字符串建立SQL连接对象，Using符号代表，范围释放的意思，SqlConnection对象会在此范围后被释放掉
            using (var ctx = ConnectionManager<SqlConnection>.GetManager(ConnectionStringNames))
            {
                IDb db = DbFactory.Instance.GetDb(ctx.Connection);
                IQuery q = db.Query();
                q.Constrain("ID").Equal(ID);
                var data = db.Select<CrmDeliverTrain>(q)[0];
                LoadProperty(IDProperty, data.ID);
                LoadProperty(CodeProperty, data.Code);
                LoadProperty(OrderProductIDProperty, data.OrderProductID);
                LoadProperty(IsSingleTrainProperty, data.IsSingleTrain);
                LoadProperty(TrainSumProperty, data.TrainSum);
                LoadProperty(BeginDateProperty, data.BeginDate);
                LoadProperty(EndDateProperty, data.EndDate);
                LoadProperty(DateSumProperty, data.DateSum);
                LoadProperty(SucceedDegreeProperty, data.SucceedDegree);
                LoadProperty(InnerValueProperty, data.InnerValue);
                LoadProperty(OutValueProperty, data.OutValue);
                LoadProperty(WellDegreeProperty, data.WellDegree);
                LoadProperty(StartUserProperty, data.StartUser);
                LoadProperty(StartDateProperty, data.StartDate);
                LoadProperty(PTeacherProperty, data.PTeacher);
                LoadProperty(TrainUserProperty, data.TrainUser);
                LoadProperty(TrainDateProperty, data.TrainDate);
                LoadProperty(TrainExplainProperty, data.TrainExplain);
                LoadProperty(ClassFrontServerProperty, data.ClassFrontServer);
                LoadProperty(ExplainProperty, data.Explain);
                LoadProperty(DegreeUserProperty, data.DegreeUser);
                LoadProperty(DegreeDateProperty, data.DegreeDate);
                LoadProperty(AddUserProperty, data.AddUser);
                LoadProperty(AddTimeProperty, data.AddTime);
                LoadProperty(DliverStateProperty, data.DliverState);
                LoadProperty(exp2Property, data.exp2);
                LoadProperty(exp3Property, data.exp3);
                LoadProperty(exp4Property, data.exp4);
                LoadProperty(exp1Property, data.exp1);
                LoadProperty(WorkFlowIdProperty, data.WorkFlowId);
                LoadProperty(WorkFlowInsIdProperty, data.WorkFlowInsId);
                LoadProperty(WorkTaskIdProperty, data.WorkTaskId);
                LoadProperty(WorkTaskInsIdProperty, data.WorkTaskInsId);
                LoadProperty(CustomerMgrProperty, data.CustomerMgr);
                LoadProperty(CustomerDirectorProperty, data.CustomerDirector);
                LoadProperty(CustomerManagerProperty, data.CustomerManager);
            }
        }

        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_DeleteSelf()
        {
            //依然是调用下面的方法删除的，只是他此时可以获得自己的Id
            DataPortal_Delete(IDProperty);
        }
        #endregion

    }
}

